import dt from '@dt/dt'
import server from '@/config/server'

function post(path, auth = true, config = true) {
  return server.api().post(path).auth(auth).config(config)
}

function get(path, auth = true, config = true) {
  return server.api().get(path).auth(auth).config(config)
}

const api = {
  create: post('/dt-order/stdBonus/createStdBonus'),
  list: get('/dt-order/stdBonus/bonusList'),
  detail: get('/dt-order/stdBonus/bonusDetail/[bonusId]'),
  submit: post('/dt-order/stdBonus/submitBonus'),
  del: post('/dt-order/stdBonus/delBonus/[bonusId]'),
  reSubmit: post('/dt-order/stdBonus/restartBonus/[bonusId]'),
  reCalculate: post('/dt-order/stdBonus/restartCal/[bonusId]'),
  personList: get('/dt-order/stdBonus/bonusDetailPerson'),
  roomList: post('/dt-order/stdBonus/bonusOrderDetail'),
  name: post('/dt-order/stdBonus/selectBonusRepeat'),
  export: get('/dt-order/stdBonus/exportBonusDetail').tag('downloadCenter'),
  nameEdit: post('/dt-order/stdBonus/bonusNameModify'),
  roomEdit: server.api().upload('/dt-order/stdBonus/operateBonus'),
  agencyEdit: server.api().upload('/dt-order/stdBonus/operateCommAdjust'),
  personEdit: post('/dt-order/stdBonus/adjustPersonBonus'),
  roomPersonEdit: post('/dt-order/stdBonus/adjustOrderBonus'),
  roomPersonChange: post('/dt-order/stdBonus/changeBonusUser'),
  updateDownload: server.api().download('/dt-order/stdBonus/downloadBonusDetail', 'get'),
  updateUpload: server.api().upload('/dt-order/stdBonus/uploadBonusDetail'),
  isCanApproveBonus: get('/dt-order/stdBonus/isCanApproveBonus'),
  radioDetail: get('/dt-order/stdBonus/bonusRadioDetail')
}

function radioDetail(bonusId) {
  return api.radioDetail.fetch({
    bonusId
  })
}

function detail(bonusId, bonusType) {
  return api.detail.fetch({
    bonusId,
    bonusType
  })
}

function create(info) {
  info.housesId = dt.buildInfo().housesId
  return api.create.fetch(info)
}

function list(info) {
  info.housesId = dt.buildInfo().housesId
  return api.list.fetch(info)
}

function submit(data) {
  //
  return api.submit.fetch(data)
}

function del(bonusId) {
  return api.del.fetch({
    bonusId
  })
}

function reSubmit(bonusId) {
  return api.reSubmit.fetch({
    bonusId
  })
}

function reCalculate(bonusId) {
  return api.reCalculate.fetch({
    bonusId
  })
}

function personList(bonusId, bonusType) {
  return api.personList.fetch({
    bonusId,
    bonusType
  })
}

function roomList(bonusId, bonusType, data) {
  return api.roomList.fetch({
    bonusId,
    bonusType,
    ...data
  })
}

function exportInfo(bonusId, bonusType) {
  return api.export.fetch({
    bonusId,
    bonusType
  })
}

function name(name) {
  return api.name.fetch({
    name,
    housesId: dt.buildInfo().housesId
  })
}

function nameEdit(bonusId, bonusName) {
  return api.nameEdit.fetch({
    bonusId,
    housesId: dt.buildInfo().housesId,
    bonusName
  })
}

function roomEdit(bonusId, orderId, commissionDetailId, isParticipate) {
  return api.roomEdit.fetch({
    bonusId,
    orderId,
    commissionDetailId: commissionDetailId || '',
    isParticipate
  })
}

function agencyEdit(bonusId, adjustId, isCancel) {
  return api.agencyEdit.fetch({
    bonusId,
    adjustId,
    isCancel
  })
}

function personEdit(bonusId, userId, adjustAmount, reason, radioStr) {
  return api.personEdit.fetch({
    bonusId,
    userId,
    adjustAmount,
    reason,
    radioStr
  })
}

function roomPersonEdit(bonusId, bonusDetailId, adjustAmount, reason) {
  return api.roomPersonEdit.fetch({
    bonusId,
    bonusDetailId,
    adjustAmount,
    reason
  })
}

function roomPersonChange(bonusDetailId, userId, userName, workNo) {
  return api.roomPersonChange.fetch({
    bonusDetailId,
    userId,
    userName,
    workNo
  })
}

function updateDownload(info) {
  return api.updateDownload.fetch(info)
}

function updateUpload(bonusId) {
  let info = {
    bonusId
  }
  let upload = api.updateUpload
  upload.setData(info)
  return upload
}

function isCanApproveBonus(housesId) {
  return api.isCanApproveBonus.fetch({
    housesId
  })
}

export default {
  radioDetail,
  create,
  detail,
  list,
  del,
  submit,
  reSubmit,
  reCalculate,
  personList,
  roomList,
  exportInfo,
  name,
  nameEdit,
  agencyEdit,
  roomEdit,
  personEdit,
  roomPersonEdit,
  roomPersonChange,
  updateDownload,
  updateUpload,
  isCanApproveBonus
}
